// 选择站点模块
var siteList = {
    el: "#uppage_pooling",
    object: "",
    area: ".area-list",
    site: ".site-list",

    // 点击区域
    clickArea: function(el){
        var _this = this;
        var areaId = $(el).data("id");
        $(_this.area).find("li").removeClass("active");
        $(el).addClass("active");
        $(_this.site).empty();

        // todo 根据areaId获取站点列表siteList
        var siteList = [
            {
                id: 111,
                city: "珠海市",
                name: "珠海城轨站"
            },
            {
                id: 222,
                city: "珠海市",
                name: "珠海城轨站"
            },
            {
                id: 333,
                city: "珠海市",
                name: "珠海城轨站"
            },
            {
                id: 444,
                city: "珠海市",
                name: "珠海城轨站"
            },
            {
                id: 555,
                city: "珠海市",
                name: "珠海城轨站"
            }
        ];

        $.each(siteList,function(index,object){
            $(_this.site).append(
                '<li data-id="'+ object.id +'">'+ 
                    object.city + '-' + object.name +
                '</li>'
            );
        });
        $(this.site).find("li").bind("click",function(){
            _this.clickSite(this);
        });
    },

    // 点击站点
    clickSite: function(el){
        var siteId = $(el).data("id");
        var name = $(el).text().split("-")[1];
        $(this.object).attr("siteid",siteId).val(name);
        this.hide();
    },

    // 显示
    show: function(object){
        this.object = "#"+object;
        $(this.el).show();
    },

    // 隐藏
    hide: function(){
        var _this = this;
        $(this.el).addClass("hide");
        setTimeout(function(){
            $(_this.el).removeClass("hide").hide();
        },500);
    },

    // 初始化
    init: function(){
        var _this = this;

        // 绑定区域点击事件
        $(this.area).find("li").bind("click",function(){
            _this.clickArea(this);
        });
        $(this.area+" li").eq(0).click();

        // 关闭窗口
        $(this.el).find(".close").bind("click",function(){
            _this.hide();
        });
    }
};


siteList.init();